var controller = {}

function getCookie(req, res){
    var cookies = {};
    req.headers.cookie && req.headers.cookie.split(';').forEach(function( cookie ) {
        var parts = cookie.split('=');
        cookies[ parts[ 0 ].trim() ] = ( parts[ 1 ] || '' ).trim();
    });
    console.log(cookies)
    return cookies;
}

controller.initBook = function(req, res, next){
    var cookies = getCookie(req, res);
    if(!cookies.u_name || cookies.u_name === '' || cookies.u_name === 'undefined'){
        console.log('重定向')
        res.redirect(301, '/');
        return;
    }
    global.USER_ACCOUNT = cookies.u_name;
    console.log('===========================',global.USER_ACCOUNT)

    res.render('index');
}

module.exports = controller;